#include "wuPlatformManager.h"

wuPlatformManager::wuPlatformManager()
{

}

wuPlatformManager::~wuPlatformManager()
{
}

void wuPlatformManager::addBitxo(ofImage *_skin, ofRectangle rect, vector <ofPoint> * _pts)
{
//	wuBase2dManager::setSimpleAmount(1);

//	wuBase2dShapeManager::addBitxo(_skin, rect, blob);

	wuSolidShape shape;
	shape.setup(box2d, _skin, rect, _pts);
//	shape.setup(box2d, _skin, rect, &simpleCountour);
	shapes.push_back(shape);
}

void wuPlatformManager::draw(bool bDrawlines, int offX)
{
        for (int i = 0; i < shapes.size(); i++)
            shapes[i].draw(bDrawlines, offX);
}

void wuPlatformManager::drawSelected(bool bDrawlines, int offX)
{
   if(selection.width < vw || selection.height < vh)
    {

        for (int i = shapes.size()-1; i >= 0; i--)
        {
            bool condi = (shapes[i].getPosition().y > selection.y) && (shapes[i].getPosition().y < selection.y + selection.height) &&
             (shapes[i].getPosition().x > selection.x + x_scroll) && (shapes[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
                shapes[i].draw(bDrawlines, offX);
        }
    }else
    {
        for (int i = 0; i < shapes.size(); i++)
            shapes[i].draw(bDrawlines, offX);
    }
}

void wuPlatformManager::clear()
{
    if(selection.width < vw || selection.height < vh)
    {

        for (int i = shapes.size()-1; i >= 0; i--)
        {
            bool condi = (shapes[i].getPosition().y > selection.y) && (shapes[i].getPosition().y < selection.y + selection.height) &&
             (shapes[i].getPosition().x > selection.x + x_scroll) && (shapes[i].getPosition().x < selection.x + x_scroll + selection.width);

            if (condi)
            {
                shapes[i].clear();
                shapes.erase(shapes.begin()+i);
            }
        }
    }else
    {
        for (int i = 0; i < shapes.size(); i++)
            shapes[i].clear();
        shapes.clear();
    }
}
